package org.ym.database.hibernate.naming;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.ym.tools.StringTool;

/**
 * 自定义命名
 * @author ym
 *
 */
public class SelfNamingStrategy extends PhysicalNamingStrategyStandardImpl {

    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {
        return new Identifier(StringUtils.lowerCase(StringTool.toUnderlineCase(name.getText())),name.isQuoted());
    }

    @Override
    public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {
        return new Identifier(StringUtils.lowerCase(StringTool.toUnderlineCase(name.getText())),name.isQuoted());
    }

    @Override
    public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
        return new Identifier(StringUtils.lowerCase(StringTool.toUnderlineCase(name.getText())),name.isQuoted());
    }
}
